class Solution {
public:
    int edgeScore(vector<int>& edges)
    {
        int n = edges.size();
        vector<long long> ans(n, 0);
        for (int i = 0; i < n; i++)
            ans[edges[i]] += i;
        long long max = -1;
        int res = -1;
        for (int i = 0; i < n; i++)
        {
            if (ans[i] > max)
            {
                res = i;
                max = ans[i];
            }

        }

        return res;

    }
};